package com.zhang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhang.entity.ShoppingCar;
import com.zhang.mapper.ShoppingCarMapper;
import com.zhang.mapper.ShoppingProductMapper;
import com.zhang.service.ShoppingCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.vo.AddProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@Service
public class ShoppingCarServiceImpl extends ServiceImpl<ShoppingCarMapper, ShoppingCar> implements ShoppingCarService {

    @Autowired
    private ShoppingCarMapper shoppingCarMapper;

    @Autowired
    private ShoppingProductMapper shoppingProductMapper;



    @Override
    public void addProductByAddProduct(AddProductVo addProductVo) {
        ShoppingCar shoppingCar = new ShoppingCar();
        shoppingCar.setUserId(addProductVo.getUid());
        shoppingCar.setProductId(addProductVo.getPid());
        shoppingCar.setCount(addProductVo.getCount());
        shoppingProductMapper.select(addProductVo.getPid());
        shoppingCar.setProductName(shoppingProductMapper.select(addProductVo.getPid()));
        shoppingCarMapper.insert(shoppingCar);


    }

    @Override
    public void deleteProuductById(String pid) {
        shoppingCarMapper.delete(pid);

    }

    @Override
    public void deleteAllProductByUserId(String uid) {
        shoppingCarMapper.deleteAll(uid);
    }
}
